package com.atf.atfconfigurator.views;


import org.apache.commons.configuration.PropertiesConfiguration;

import com.atf.atfconfigurator.AtfconfiguratorUI;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;

import com.vaadin.ui.FormLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;


public class InfoViews extends VerticalLayout implements View{
	private PropertiesConfiguration wasConfigProperty;
	@Override
	public void enter(ViewChangeEvent event) {
		// TODO Auto-generated method stub

		wasConfigProperty=((AtfconfiguratorUI) getUI()).getWasConfiguration();	
		setSpacing(true);
        setMargin(true);

        Label title = new Label(wasConfigProperty.getString("appName"));
        title.addStyleName("h2");
        title.addStyleName("colored");
        addComponent(title);
        
		final FormLayout form = new FormLayout();
        form.setMargin(false);
        form.setSpacing(true);
        form.setWidth("100%");
        //form.set
        form.addStyleName("light");
        addComponent(form);
        
        
        Label section = new Label("Info");
        section.addStyleName("h2");
        section.addStyleName("colored");
        form.addComponent(section);
        
        //application Name
        final TextField name = new TextField("Application name");
        name.setWidth("50%");
        name.setValue(wasConfigProperty.getString("appName"));
        name.setReadOnly(true);
        form.addComponent(name);
        
       //Department Name
        final TextField dName = new TextField("Department name");
        dName.setWidth("50%");
        dName.setValue(wasConfigProperty.getString("departmentName",""));
        dName.addValueChangeListener(new Property.ValueChangeListener(){

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				String value = (String) event.getProperty().getValue();
				((AtfconfiguratorUI) getUI()).getWasConfiguration().setProperty("departmentName", value);
			}
        	
        });
        form.addComponent(dName);
        
        //Department Name
        final TextField env = new TextField("Environment");
        env.setValue(wasConfigProperty.getString("Environment",""));
        env.addValueChangeListener(new Property.ValueChangeListener(){

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				String value = (String) event.getProperty().getValue();
				((AtfconfiguratorUI) getUI()).getWasConfiguration().setProperty("Environment", value);
			}
        	
        });
        env.setWidth("50%");
        form.addComponent(env);
        
        //Department Name
        final TextField wPath = new TextField("Webapp Path");
        wPath.setValue(wasConfigProperty.getString("webappsPath",""));
        env.addValueChangeListener(new Property.ValueChangeListener(){

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				String value = (String) event.getProperty().getValue();
				((AtfconfiguratorUI) getUI()).getWasConfiguration().setProperty("webappsPath", value);
			}
        	
        });
        wPath.setWidth("50%");
        form.addComponent(wPath); 
        
	}

	

}
